
<?php $this->headScript()->appendFile($this->publicUrl . "Scripts/jquery.js"); ?>
<?php $this->headScript()->captureStart() ?>

	$(document).ready( function() {
		$("#author").change( function() {
			var id=$("#author option:selected").attr('value');
			if ( id == '-1' ) return;
			var url = '<?= $this->url(array('controller'=>'book','action'=>'get-books-by-author'), 'ajax') ?>' + 
				'?id=' + id;
				 
			$.get( url, function (data) {
				$("#related-div").hide(250);
				$("#book").html('');					
				var data = eval(data);
				
				for(i=0; i<data.length; i++) {
					$("#book").append('<option value="' + data[i].id + '">' + data[i].name + '</option>');	
				}
				
				$("#book").change();
			});						
		});		
		
		$("#book").change( function() {
			var id=$("#book option:selected").attr('value');
			var url = '<?= $this->url(array('controller'=>'book','action'=>'get-related'), 'ajax') ?>' + 
				'?id=' + id;
				
			$.get( url, function (data) {				
				$("#related").html('');
				data = eval(data);
				for(i=0; i<data.length; i++) {
					$("#related").append('<li>' + data[i].name + ' by ' + data[i].author + 
						', description:' + data[i].description + '</li>');
				}			
				$("#related-div").show(750);
			}); 
		});
	});

<?php $this->headScript()->captureEnd() ?>


<div>
	<ul>
		<?php foreach( $this->templates as $tmp ) { ?>
			<ul>
				<a href="<?= $this->url(array('templateId'=>strtolower($tmp->getName()))) ?>">
					<?= $tmp->getName() ?>
				</a> 
			</ul>
		<?php } ?>
	</ul>	
</div>


<h1><?= $this->translate('welcome_headline'); ?></h1>

<div><?= $this->translate('welcome_body') ?></div>


<?= $this->translate('choose'); ?>

<select name="author" id="author">
	<option selected value="-1"></option>
	<?php foreach($this->authors as $author) { ?>
	<option value="<?= $author['id'] ?>"><?= $author['name'] ?></option>
	<?php } ?>
</select>

<select name="book" id="book">
</select>

<div id="related-div" style="display:none; margin-top:10px">
	<h3><?= $this->translate('recomended') ?></h3>
	<ul id="related">
	</ul>
	
	<small style="margin-top:60px">
		<?= $this->translate('source') ?>
	</small>	
</div>

